/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/
package forge

import (
	"github.com/spf13/cobra"
	"satellite/app/forge"
	"satellite/pkg/errorx"
	"time"
)

var Cmd = forgeCmd

// forgeCmd represents the forgeCmd command
var forgeCmd = &cobra.Command{
	Use:   "forge",
	Short: "测试数据库",
	Long:  ``,
	Run: func(cmd *cobra.Command, args []string) {
		_ = cmd.Help()
	},
}

var (
	baseOption = new(forge.BaseOption)
	base       = forge.NewBase(baseOption)
)

func init() {
	forgeCmd.Flags().StringVarP(&baseOption.Name, "name", "", "", "资源名称")
	forgeCmd.Flags().StringVarP(&baseOption.Namespace, "namespace", "n", "", "资源所在命名空间")
	forgeCmd.Flags().DurationVarP(&baseOption.Timeout, "timeout", "t", 10*time.Second, "资源超时")
	connectCmd.Flags().AddFlagSet(forgeCmd.Flags())
	offlineCmd.Flags().AddFlagSet(forgeCmd.Flags())
}

func Args(cmd *cobra.Command, args []string) error {
	if baseOption.Name == "" && len(args) == 0 {
		return errorx.MissNameErr
	}
	if baseOption.Name == "" {
		baseOption.Name = args[0]
	}
	baseOption.Fill()
	return nil
}
